import {
	ref
} from "vue";

import {
	useUserStore
} from "../../stores/useUserStore.js";

import {
	useUserApis
} from "../../request/user.api.js";

export function useController() {
	const userStore = useUserStore();
	const apis = useUserApis();

	const formData = ref({
		mobile: '13211112222',
		password: '123456',
	});


	async function login() {
		const {
			mobile,
			password
		} = formData.value;

		await apis.login({
			mobile,
			password
		});

		uni.reLaunch({
			url: "/pages/index/index"
		});
	}

	function guestLogin() {
		userStore.guestLogin();
		uni.reLaunch({
			url: "/pages/index/index"
		});
	}

	return {
		formData,

		login,
		guestLogin,
	}
}